<?php
class Request
{
    //获取post和get参数
    public static function get($key, $default = null)
    {
        if (isset($_GET[$key])) {
            return $_GET[$key];
        } else if (isset($_POST[$key])) {
            return $_POST[$key];
        } else {
            return $default;
        }
    }
    public static function post($key, $default = null)
    {
        if (isset($_POST[$key])) {
            return $_POST[$key];
        } else {
            return $default;
        }
    }

    // 获取任意get、post参数
    public static function param($key, $default = null)
    {
        if (isset($_GET[$key])) {
            return $_GET[$key];
        } else if (isset($_POST[$key])) {
            return $_POST[$key];
        } else {
            return $default;
        }
    }

    // 设置Session
    public static function setSession($key, $value)
    {
        $_SESSION[$key] = $value;
    }
    // 获取Session
    public static function getSession($key, $default = null)
    {
        if (isset($_SESSION[$key])) {
            return $_SESSION[$key];
        } else {
            return $default;
        }
    }
    // 删除Session
    public static function delSession($key)
    {
        unset($_SESSION[$key]);
    }
    // 清空Session
    public static function clearSession()
    {
        session_unset();
        session_destroy();
    }
    // 设置Cookie
    public static function setCookie($key, $value, $expire = 0, $path = '/', $domain = '')
    {
        setcookie($key, $value, $expire, $path, $domain);
    }
    // 获取Cookie
    public static function getCookie($key, $default = null)
    {
        if (isset($_COOKIE[$key])) {
            return $_COOKIE[$key];
        } else {
            return $default;
        }
    }
}
